package algorithm;

import java.util.ArrayList;
import java.util.List;

public class leetcode_0131 {
    public List<List<String>> partition(String s) {
        List<List<String>> list=new ArrayList<>();
        List<String> path=new ArrayList<>();
        if("".equals(s)) return list;
        dfs(list,path,s,0);
        return list;
    }
    public void dfs(List<List<String>> list,List<String> path,String s,int start){
        if(start==s.length()) {
            list.add(new ArrayList<>(path));
            return;
        }
        for(int i=start+1;i<=s.length();++i){
            if(isreverse(s,start,i-1)){
                path.add(s.substring(start,i));
                dfs(list,path,s,i);
                path.remove(path.size()-1);
            }
        }

    }
    public boolean isreverse(String s,int start,int end){

        while(start<end){
            if(s.charAt(start)!=s.charAt(end)) return false;
            start++;end--;
        }
        return true;
    }
}
